dcmotor32 2.2.0
Loading...
Searching...
No Matches
dcmotor32.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef DCMOTOR32_H
29#define DCMOTOR32_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_analog_in.h"
52
58
63
68
73#define DCMOTOR32_CONTROL_SDO_SEL_CONTROL 0x00
74#define DCMOTOR32_CONTROL_SDO_SEL_STATUS 0x80
75#define DCMOTOR32_CONTROL_SDO_SEL_MASK 0x80
76#define DCMOTOR32_CONTROL_MODE_PD_GND_OUT 0x00
77#define DCMOTOR32_CONTROL_MODE_PU_SHORT_TO_GND 0x08
78#define DCMOTOR32_CONTROL_MODE_SLOW_DECAY_LSB 0x10
79#define DCMOTOR32_CONTROL_MODE_SLOW_DECAY_LSA 0x18
80#define DCMOTOR32_CONTROL_MODE_FAST_DECAY_HSB 0x20
81#define DCMOTOR32_CONTROL_MODE_FAST_DECAY_HSB_OPEN_LOAD 0x28
82#define DCMOTOR32_CONTROL_MODE_FORWARD_HSB 0x30
83#define DCMOTOR32_CONTROL_MODE_FORWARD_LSA 0x38
84#define DCMOTOR32_CONTROL_MODE_FAST_DECAY_HSA_OPEN_LOAD 0x40
85#define DCMOTOR32_CONTROL_MODE_FAST_DECAY_HSA 0x48
86#define DCMOTOR32_CONTROL_MODE_REVERSE_LSB 0x50
87#define DCMOTOR32_CONTROL_MODE_REVERSE_HSA 0x58
88#define DCMOTOR32_CONTROL_MODE_SLOW_DECAY_HSB 0x60
89#define DCMOTOR32_CONTROL_MODE_SLOW_DECAY_HSA 0x68
90#define DCMOTOR32_CONTROL_MODE_HALF_BRIDGE_A_TRI_STATE 0x70
91#define DCMOTOR32_CONTROL_MODE_HALF_BRIDGE_B_TRI_STATE 0x78
92#define DCMOTOR32_CONTROL_MODE_MASK 0x78
93#define DCMOTOR32_CONTROL_CURRENT_SENSE_DISABLE 0x00
94#define DCMOTOR32_CONTROL_CURRENT_SENSE_ENABLE 0x04
95#define DCMOTOR32_CONTROL_CURRENT_SENSE_MASK 0x04
96#define DCMOTOR32_CONTROL_SLEW_RATE_SLOW 0x00
97#define DCMOTOR32_CONTROL_SLEW_RATE_FAST 0x02
98#define DCMOTOR32_CONTROL_SLEW_RATE_MASK 0x02
99#define DCMOTOR32_CONTROL_EN_DISABLE 0x00
100#define DCMOTOR32_CONTROL_EN_ENABLE 0x01
101#define DCMOTOR32_CONTROL_EN_MASK 0x01
102
107#define DCMOTOR32_STATUS_SDO_SEL_CONTROL 0x00
108#define DCMOTOR32_STATUS_SDO_SEL_STATUS 0x80
109#define DCMOTOR32_STATUS_SDO_SEL_MASK 0x80
110#define DCMOTOR32_STATUS_OCA_MASK 0x40
111#define DCMOTOR32_STATUS_OCB_MASK 0x20
112#define DCMOTOR32_STATUS_OL_MASK 0x10
113#define DCMOTOR32_STATUS_UV_MASK 0x08
114#define DCMOTOR32_STATUS_TSDA_MASK 0x04
115#define DCMOTOR32_STATUS_TSDB_MASK 0x02
116#define DCMOTOR32_STATUS_EN_MASK 0x01
117
122#define DCMOTOR32_R8 1000.0
123#define DCMOTOR32_R9 820.0
124
129#define DCMOTOR32_NUM_CONVERSIONS 200
130
135#define DCMOTOR32_VREF_3V3 3.3
136#define DCMOTOR32_VREF_5V 5.0
137#define DCMOTOR32_VREF_DEFAULT DCMOTOR32_VREF_3V3
138
143#define DCMOTOR32_TIMEOUT_MS 2000
144 // dcmotor32_set
146
151
156
161#define DCMOTOR32_MAP_MIKROBUS( cfg, mikrobus ) \
162 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
163 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
164 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
165 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
166 cfg.is_pin = MIKROBUS( mikrobus, MIKROBUS_AN )
167 // dcmotor32_map // dcmotor32
170
175typedef struct
176{
177 digital_out_t mosi;
178 digital_out_t sck;
179 digital_out_t cs;
180 digital_in_t miso;
181 analog_in_t adc;
182
183 uint8_t control;
184 uint8_t status;
186
188
193typedef struct
194{
195 // Communication gpio pins
196 pin_name_t miso;
197 pin_name_t mosi;
198 pin_name_t sck;
199 pin_name_t cs;
200
201 // Additional gpio pins
202 pin_name_t is_pin;
203
204 analog_in_resolution_t resolution;
205 float vref;
206
208
219
225
236
251
265
277err_t dcmotor32_set_control ( dcmotor32_t *ctx, uint8_t control );
278
290
302err_t dcmotor32_set_operation_mode ( dcmotor32_t *ctx, uint8_t mode );
303
315
327
339
351
363
375
387err_t dcmotor32_read_adc_raw ( dcmotor32_t *ctx, uint16_t *data_out );
388
402err_t dcmotor32_read_adc_volt ( dcmotor32_t *ctx, float *data_out );
403
417err_t dcmotor32_read_adc_volt_avg ( dcmotor32_t *ctx, uint16_t num_conv, float *volt_avg );
418
430err_t dcmotor32_set_adc_vref ( dcmotor32_t *ctx, float vref );
431
443
455err_t dcmotor32_get_out_current ( dcmotor32_t *ctx, float *current );
456
457#ifdef __cplusplus
458}
459#endif
460#endif // DCMOTOR32_H
461 // dcmotor32
463
464// ------------------------------------------------------------------------ END
dcmotor32_return_value_t
DC Motor 32 Click return value data.
Definition dcmotor32.h:214
@ DCMOTOR32_ERROR
Definition dcmotor32.h:216
@ DCMOTOR32_OK
Definition dcmotor32.h:215
err_t dcmotor32_read_adc_raw(dcmotor32_t *ctx, uint16_t *data_out)
DC Motor 32 read raw IS ADC value function.
err_t dcmotor32_get_out_current(dcmotor32_t *ctx, float *current)
DC Motor 32 get output current function.
err_t dcmotor32_read_adc_volt_avg(dcmotor32_t *ctx, uint16_t num_conv, float *volt_avg)
DC Motor 32 read IS pin voltage level average function.
err_t dcmotor32_set_fast_slew_rate(dcmotor32_t *ctx)
DC Motor 32 set fast slew rate function.
err_t dcmotor32_disable_device(dcmotor32_t *ctx)
DC Motor 32 disable device function.
err_t dcmotor32_enable_isense(dcmotor32_t *ctx)
DC Motor 32 enable current sense function.
err_t dcmotor32_read_adc_volt(dcmotor32_t *ctx, float *data_out)
DC Motor 32 read IS pin voltage level function.
err_t dcmotor32_enable_device(dcmotor32_t *ctx)
DC Motor 32 enable device function.
void dcmotor32_cfg_setup(dcmotor32_cfg_t *cfg)
DC Motor 32 configuration object setup function.
err_t dcmotor32_set_slow_slew_rate(dcmotor32_t *ctx)
DC Motor 32 set slow slew rate function.
err_t dcmotor32_set_control(dcmotor32_t *ctx, uint8_t control)
DC Motor 32 set control function.
err_t dcmotor32_calib_offset(dcmotor32_t *ctx)
DC Motor 32 calibrate offset function.
err_t dcmotor32_disable_isense(dcmotor32_t *ctx)
DC Motor 32 disable current sense function.
err_t dcmotor32_init(dcmotor32_t *ctx, dcmotor32_cfg_t *cfg)
DC Motor 32 initialization function.
err_t dcmotor32_default_cfg(dcmotor32_t *ctx)
DC Motor 32 default configuration function.
err_t dcmotor32_set_operation_mode(dcmotor32_t *ctx, uint8_t mode)
DC Motor 32 set operation mode function.
err_t dcmotor32_set_adc_vref(dcmotor32_t *ctx, float vref)
DC Motor 32 set vref function.
err_t dcmotor32_get_status(dcmotor32_t *ctx)
DC Motor 32 get status function.
DC Motor 32 Click configuration object.
Definition dcmotor32.h:194
pin_name_t is_pin
Definition dcmotor32.h:202
analog_in_resolution_t resolution
Definition dcmotor32.h:204
float vref
Definition dcmotor32.h:205
pin_name_t sck
Definition dcmotor32.h:198
pin_name_t mosi
Definition dcmotor32.h:197
pin_name_t miso
Definition dcmotor32.h:196
pin_name_t cs
Definition dcmotor32.h:199
DC Motor 32 Click context object.
Definition dcmotor32.h:176
digital_out_t cs
Definition dcmotor32.h:179
digital_out_t sck
Definition dcmotor32.h:178
digital_out_t mosi
Definition dcmotor32.h:177
digital_in_t miso
Definition dcmotor32.h:180
float zero_curr_offset
Definition dcmotor32.h:185
uint8_t status
Definition dcmotor32.h:184
uint8_t control
Definition dcmotor32.h:183
analog_in_t adc
Definition dcmotor32.h:181